package com.hnas.eCard.dao.impl;

import java.util.Date;

import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

import com.hnas.api.util.DateUtil;
import com.hnas.core.dao.BaseDaoImpl;
import com.hnas.core.util.StringUtil;
import com.hnas.eCard.dao.EntityDenominationReDao;
import com.hnas.eCard.orm.EntityDenominationRe;

@Component("entityDenominationReDao")
public class EntityDenominationReDaoImpl extends BaseDaoImpl<EntityDenominationRe> implements EntityDenominationReDao{

	public EntityDenominationReDaoImpl() {
		super(EntityDenominationRe.class);
	}

	@Override
	public EntityDenominationRe saveOrUpdate(EntityDenominationRe entity) {
		EntityDenominationRe vo = null;
		try {
			if(entity != null){
				String id = entity.getId();
				if(StringUtil.isNotEmpty(id)){
					vo = this.find(id);
				}	
				if(vo == null){//新增
					vo = new EntityDenominationRe();
					BeanUtils.copyProperties(entity, vo);
					vo.setCreateTime(DateUtil.dateTimeToString(new Date()));
					vo.setUpdateTime(DateUtil.dateTimeToString(new Date()));
					vo.setIsDeleted(false);
					this.persist(vo);
				}else{//修改
					BeanUtils.copyProperties(entity, vo);
					vo.setUpdateTime(DateUtil.dateTimeToString(new Date()));
					this.merge(vo);
				}
			}
			return vo;
		} catch (Exception e) {
			e.printStackTrace();
			return vo;
		}
	}

}
